package cj.web.yc.controllers;

import java.util.List;
import java.util.Map;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import cj.web.yc.domain.WatchHistory;
import cj.web.yc.service.WatchHistoryService;

@Path("/watchHistory")
public class WatchHistoryController{

	private static Logger logger = Logger.getLogger(WatchHistoryController.class.getName());
	
	@Autowired
	private WatchHistoryService watchHistoryService;
	
	@Get("show")
	public String show(Model model) {
		return "/views/yc/watchHistoryList.vm";
	}

	@Post("getList")
	public String queryList(WatchHistory watchHistory) {
	
		//当前页  
		watchHistory.setStart((watchHistory.getPage()-1)*watchHistory.getRows());
		watchHistory.setLength(watchHistory.getRows());
		
		JSONObject jo = new JSONObject();
		
		Map rep = watchHistoryService.query(watchHistory);
		List<WatchHistory> objs = (List<WatchHistory>) rep.get("watchHistorylis");
		int size = (int) rep.get("size");
		
		jo.put("rows", objs);
		jo.put("total", size);
		return "@"+jo.toString();
	}
}
